﻿Imports Microsoft.Practices.Composite.Modularity
Imports Microsoft.Practices.Unity
Imports EHaskins.Frc.Infrastructure
Imports Microsoft.Practices.Composite.Regions

Public Class OutputModule
    Implements IModule

    Dim _container As IUnityContainer
    Dim _dashboard As IDashboardController
    Dim _regionManager As IRegionManager

    ''' <summary>
    ''' Initializes a new instance of the OutputModule class.
    ''' </summary>
    ''' <param name="container"></param>
    ''' <param name="dashboard"></param>
    ''' <param name="regionManager"></param>
    Public Sub New(ByVal container As IUnityContainer, ByVal dashboard As IDashboardController, ByVal regionManager As IRegionManager)
        _container = container
        _dashboard = dashboard
        _regionManager = regionManager
    End Sub

    Public Sub Initialize() Implements Microsoft.Practices.Composite.Modularity.IModule.Initialize
        RegisterViewsAndServices()
        _dashboard.Processors.Add(_container.Resolve(Of IOutputDataProcessor)())

        Dim viewModel = _container.Resolve(Of IOutputViewModel)()
        Dim view = viewModel.View
        Dim region = _regionManager.Regions(Regions.MainContent)
        region.Add(view)
        region.Activate(view)
    End Sub
    Private Sub RegisterViewsAndServices()
        _container.RegisterType(Of IOutputDataProcessor, OutputDataProcessor)(New ContainerControlledLifetimeManager)
        _container.RegisterType(Of IOutputViewModel, OutputViewModel)()
        _container.RegisterType(Of OutputView, OutputView)()
    End Sub
End Class
